import BaseEditor from './BaseEditor';
import { ResourceLoader } from './DataResource';

export default class TaskLoadManager {
  editor;

  constructor(editor) {
    this.editor = editor;
  }

  loadFrame(index, showLoading = true, force = false) {
    const { isSeriesFrame, frameIndex, frames } = this.editor.state;
    this.editor.state.frameIndex = index;
    this.loadResource()
  }

  loadClassification() {}

  loadObjectAndClassification() {}

  loadAllClassification() {}

  loadAllObjects() {}

  loadResource() {
    let { frames, frameIndex } = this.editor.state;
    // console.log(frames, "frames");
    let frame = frames[frameIndex];
    let resource = this.editor.dataResource.getResource(frame);
    if (resource instanceof ResourceLoader) {
      return resource
      .get()
      .then((data) => {
        console.log('load Resource', data);
        this.setResource(data);
      })
      .catch((e) => {
        // this.editor.handleErr(e, this.editor.lang('load-resource-error'));
      })
    }
    //  else {
    //   this.setResource(resource)
    // }
  }
  setResource(data) {
    this.editor.viewManager.setImgViews(data.viewConfig);
    // if (!this.playManger.playing) this.editor.setImgViews(data.viewConfig);
    // this.editor.setPointCloudData(data.pointsData, 0);
    this.editor.setPointCloudData(data.pointsData, data.ground || 0, data.intensityRange);
  }
}